package com.wake.mycomposebook.ui.home

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.*
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Nightlight
import androidx.compose.material.icons.filled.Pattern
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.wake.mycomposebook.ui.sys.AppThemeState
import com.wake.mycomposebook.utils.TestTags
import com.wake.mycomposebook.utils.showLog

/**
 *@author created by WA03675
 *@date  2022-04-12 14:37
 *@des
 */

/**
主屏幕显示的视图
1.标题
title
页面模式
调色板
2.内容
list
 */
@Composable
fun MyHomeScreen(appThemeState: MutableState<AppThemeState>) {
    Scaffold(
        Modifier.testTag(TestTags.HOME_SCREEN_ROOT),
        topBar = {
            TopAppBar(
                modifier = Modifier
                    .fillMaxWidth()
                    .height(50.dp),
                backgroundColor = MaterialTheme.colors.background
            ) {
                Text(text = "Hello Compose", Modifier.weight(1f), fontSize = 16.sp, fontWeight = FontWeight.Bold)

                IconButton(onClick = { darkTheme() }) {
                    Icon(
                        imageVector = Icons.Filled.Nightlight, contentDescription = null
                    )
                }
                IconButton(onClick = { pattern() }) {
                    Icon(
                        imageVector = Icons.Filled.Pattern, contentDescription = null
                    )
                }
            }

        }

    ) {
        HomeContent()
    }
}

fun darkTheme() {
    showLog("我被点击了")
}

fun pattern() {
    showLog("调色板")
}

@Composable
fun HomeContent() {
    Column {
        repeat(10) {
//            Row(
//                modifier = Modifier
//                    .padding(15.dp)
//                    .fillMaxWidth()
//                    .height(40.dp)
//                    .background(Color.Cyan, RoundedCornerShape(10.dp)),
//                verticalAlignment = Alignment.CenterVertically,
//                horizontalArrangement = Arrangement.Center
//            ) {
//                Text(
//                    text = "第${it}个",
//                    fontSize = 16.sp,
//                )
//            }

            Text(
                text = "bt $it",
                modifier = Modifier
                    .padding(16.dp)
                    .background(Color.Cyan, RoundedCornerShape(10.dp))
                    .fillMaxWidth()
                    .padding(16.dp),
                textAlign = TextAlign.Center,
                color = Color.Red
            )

//            androidx.compose.material3.Button(
//                onClick = { },
//                modifier = Modifier
//                    .fillMaxWidth()
//                    .padding(16.dp)
//                    .testTag("bt $it")
//            ) {
//                Text(
//                    text = "bt $it",
//                    modifier = Modifier.padding(8.dp),
//                    style = androidx.compose.material3.MaterialTheme.typography.labelLarge
//                )
//            }

            //Material3Card(
//                modifier = Modifier
//                    .padding(15.dp)
//                    .fillMaxWidth()
//                    .height(40.dp),
//                shape = RoundedCornerShape(10.dp),
//                backgroundColor = androidx.compose.material3.MaterialTheme.colorScheme.primary,
//                contentColor = androidx.compose.material3.MaterialTheme.colorScheme.onPrimary,
//                elevation = 5.dp
//            ) {
//                Text(
//                    text = "第${it}个",
//                    modifier = Modifier.padding(10.dp),
//                    style = androidx.compose.material3.MaterialTheme.typography.titleMedium
//                )
//            }
        }
    }
}


@Preview
@Composable
fun PreviewUi() {
    MyHomeScreen(appThemeState = remember {
        mutableStateOf(AppThemeState())
    })
}